package data_report

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/analysisClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type GameReportLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 游戏报表
func NewGameReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GameReportLogic {
	return &GameReportLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GameReportLogic) GameReport(req *types.GameReportRequest) (resp types.GameReportResponse, err error) {
	resp = types.GameReportResponse{
		Data:     make([]types.GameReportData, 0),
		Page:     req.Page,
		PageSize: req.PageSize,
		Total:    0,
	}

	reqq := &rpc.GameReportRequest{
		GameType:  req.GameType,
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		Page:      req.Page,
		PageSize:  req.PageSize,
	}

	analysis, err := l.svcCtx.Analysis.GamesAnalysis(l.ctx, reqq)
	if err != nil {
		return types.GameReportResponse{}, err
	}

	for _, v := range analysis.Data {
		t := types.GameReportData{
			GameType:    v.GameType,
			GameName:    v.GameName,
			OrderAmount: v.OrderAmount,
			Fee:         v.Fee,
			Prizes:      v.Fee,
			GameWinLose: v.GameWinLose,
		}
		resp.Data = append(resp.Data, t)
	}
	resp.Total = analysis.Total
	return
}
